var _that;
var _chooseCallBack;
var topval;
function init(target, items, top, chooseCallBack) {
  _that = target;
  _chooseCallBack = chooseCallBack;
  _that.setData({
    cgr_show: false,
    cgritems: items,
    cur_cgr: 0
  });

  topval = top;

  if (_that.animation == null || _that.animation == undefined) {
    _that.animation = wx.createAnimation({
      duration: 300,
      timingFunction: 'ease-out',
      // 延迟多长时间开始
      delay: 0,
      transformOrigin: 'left bottom 0',
      success: function (res) {
        console.log(res)
      }
    });
  }
}

function show() {
  if(_that.data.cgr_show == true){
    close();
    return;
  }
  _that.setData({
    cgr_show: true,
    cgrs_top: -200
  });

  _that.animation.top(topval).step();

  _that.setData({
    cgr_amt: _that.animation.export()
  });
}

function close() {
  _that.setData({
    cgr_show: false
  });
}

function choose(e) {
  var cgrindex = e.currentTarget.dataset.cgrindex;
  _that.setData({
    cur_cgr: cgrindex
  });

  _chooseCallBack(_that.data.cgritems[cgrindex]);
}

module.exports = {
  init: init,
  show: show,
  close: close,
  choose: choose,
}